package com.heima.leetcode.practice;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author 勾新杰
 * @version 1.0
 * @description: leetcode 173. 二叉搜索树迭代器
 * @date 2025/9/29 8:40
 */
public class E173 {
    static class BSTIterator {
        List<Integer> list = new ArrayList<>();

        Iterator<Integer> iterator;

        private void inOrder(TreeNode root){
            if(root == null) return;
            inOrder(root.left);
            list.add(root.val);
            inOrder(root.right);
        }

        public BSTIterator(TreeNode root) {
            inOrder(root);
            iterator = list.iterator();
        }

        public int next() {
            return iterator.next();
        }

        public boolean hasNext() {
            return iterator.hasNext();
        }
    }
}
